package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo8 {
    public static void main(String[] args) {
        System.out.println("请输入用户名、密码、昵称、年龄");
        Scanner sc = new Scanner(System.in);
        try (Connection connection = DBUtil.getConnection();){
            String sql = "insert into user(username,password,nickname,age) " +
                    "values(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
          /*  ps.setString(1,"张三");
            ps.setString(2,"123456");
            ps.setString(3,"三儿");
            ps.setInt(4,18);*/
            ps.setString(1,sc.next());
            ps.setString(2,sc.next());
            ps.setString(3,sc.next());
            ps.setInt(4,sc.nextInt());
            int num = ps.executeUpdate();
            System.out.println(num>0?"注册成功":"注册失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
